//
//  PhysicSprite.m
//  Box2DProject
//
//  Created by Thi Huynh on 9/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "PhysicSprite.h"

@implementation PhysicSprite
@synthesize imgFileName     = _imgFileName;
@synthesize body            = _body;
@synthesize position        = _position;
@synthesize originalRect    = _originalRect;


- (id)initWithWorld:(b2World*)world imageName:(NSString*)imageName pos:(CGPoint)pos
{
    self = [super initWithFile:imageName];
    if(self)
    {
        
    }
    return self;
}

-(b2Body*)createBodyForWorld:(b2World *)world position:(b2Vec2)position rotation:(float)rotation vertices:(b2Vec2*)vertices vertexCount:(int32)count density:(float)density friction:(float)friction restitution:(float)restitution
{
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position = position;
    bodyDef.angle = rotation;
    b2Body *body = world->CreateBody(&bodyDef);
    
    b2FixtureDef fixtureDef;
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.restitution = restitution;
    fixtureDef.filter.categoryBits = 0;
    fixtureDef.filter.maskBits = 0;
    fixtureDef.isSensor = YES;
    
    b2PolygonShape shape;
    shape.Set(vertices, count);
    fixtureDef.shape = &shape;
    body->CreateFixture(&fixtureDef);
    
    return body;
}

@end
